package view.PlantUml;


import java.util.ArrayList;
import java.util.Map;

import view.interfaces.Iview;

import Model.Actor;
import Model.Association;
import Model.Classe;
import Model.Usecase;
import Model.diagram.UsecasDiagram;
import Model.interfaces.Iassociation;
import Model.interfaces.Idiagrame;

public class PlantUmlUsecase implements Iview{
private UsecasDiagram dia;
private  String Source="";
	
public PlantUmlUsecase(){
	
}

@Override
	public void addDiagram(Idiagrame diagram) {
		this.dia=(UsecasDiagram) diagram;
		
	}
	@Override
	public void convert() {
	for( Map.Entry<String, Classe> valclass : dia.getClasMap().entrySet()){
		if(valclass.getValue() instanceof Actor){
			
			setSource((":"+valclass.getValue().getName()+":\n"));
		}
		if(valclass.getValue() instanceof Usecase){
			setSource(("("+valclass.getValue().getName()+")\n"));
		}
	}
	
	for(Map.Entry<String, Iassociation> kaboom : dia.getAssociationmap().entrySet()){
			if(kaboom.getValue() instanceof Association){
			ArrayList<Classe> hey=((Association) kaboom.getValue()).getClas();
			String bufer=null;
			String Result=null;
			for(Classe r : hey){
				
				
				 if(r instanceof Actor){
					
					
						Result=":"+r.getName()+":";
					
					
				}else{
					 bufer="("+r.getName()+")";
				}
			}
			setSource(Result+"--"+bufer+"\n");
			}
		}
	}

	public String getSource() {
		return "@startuml\n"+Source+"@enduml\n";
	}

	public void setSource(String source) {
		Source += source;
	}

	@Override
	public String getCode() {
		// TODO Auto-generated method stub
		return "@startuml\n"+Source+"@enduml\n";
	}
	
	
	

}
